// pages/myself/apply/apply.js
const {getActivityRegistration} = require("../../../utils/http/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    applyList:[ ],
    statusMap: {
      0: { text: '待审核', color: 'warning' },
      1: { text: '已审核', color: 'success' },
      2: { text: '待付款', color: 'primary' },
      3: { text: '未到场', color: 'danger' },
      4: { text: '已到场', color: 'success' }
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getActivityRegistration()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getActivityRegistration()
  },
  
  goActiveDetail(e){
    console.log("跳转活动详情页面",e)
    let item = e.currentTarget.dataset.item
    if(item.activityType == 0){
      wx.navigateTo({
        url: '../../index/live/live?activityId='+ item.activityId,
      })
    }else{
      wx.navigateTo({
        url: '../../activeDetail/activeDetail?url='+ item.activityImage,
      })
    }
  },
  
  getActivityRegistration(){
    getActivityRegistration(3).then(res => {
      console.log("报名活动",res)
      let activityList = []
      res.rows.forEach(item => {
        // 合并活动信息和注册状态
        const activity = {
          ...item.activity,
          registrationStatus: item.registrationStatus || 0
        }
        activityList.push(activity)
      })
      this.setData({
        applyList: activityList
      })
    })
  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getActivityRegistration()
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})